package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;

import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.service.ISysDeptService;

/**
 * 部门内部Controller，实现远程feign接口com.ruoyi.system.api.RemoteSysDeptService。
 * 
 * @author ruoyi
 * @date 2023-04-27
 */
@RestController
@RequestMapping("/inner/dept")
public class SysDeptInnerController
{
    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询部门列表
     */
    @InnerAuth
    @PostMapping("/list")
    public R<List<SysDept>> selectSysDeptList(SysDept sysDept)
    {
        List<SysDept> list = sysDeptService.selectDeptList(sysDept);
        return R.ok(list);
    }

    /**
     * 获取部门详细信息
     */
    @InnerAuth
    @GetMapping(value = "/{deptId}")
    public R<SysDept> selectSysDeptByDeptId(@PathVariable("deptId") Long deptId)
    {
        SysDept sysDept = sysDeptService.selectDeptById(deptId);
        return R.ok(sysDept);
    }

    /**
     * 新增部门
     */
    @InnerAuth
    @PostMapping
    public R<Integer> insertSysDept(@RequestBody SysDept sysDept)
    {
        Integer result = sysDeptService.insertDept(sysDept);
        return R.ok(result);
    }

    /**
     * 修改部门
     */
    @InnerAuth
    @PutMapping
    public R<Integer> updateSysDept(@RequestBody SysDept sysDept)
    {
        Integer result = sysDeptService.updateDept(sysDept);
        return R.ok(result);
    }

    /**
     * 批量删除部门
     */
	@InnerAuth
	@DeleteMapping("/{deptIds}")
    public R<Integer> deleteSysDeptByDeptIds(@PathVariable Long deptIds)
    {
        Integer result = sysDeptService.deleteDeptById(deptIds);
        return R.ok(result);
    }

}
